package com.example.demo.jucConcurrent.LockSupport;

import java.util.concurrent.locks.LockSupport;

public class ParkAndUnparkDemo {
    public static void main(String[] args) {

        MyThread myThread = new MyThread(Thread.currentThread());
        myThread.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("before park");
        //获取许可证
        LockSupport.park("ParkAndUnParkDemo");
        System.out.println("after park");
    }
}

class  MyThread extends  Thread{

    private  Object object;

    public MyThread(Object object) {
        this.object = object;
    }

    @Override
    public void run() {
        System.out.println("before unpark");
        //释放许可
        LockSupport.unpark((Thread)object);
        System.out.println("after unPark");
    }
}
